Skip to content

Instantly share code, notes, and snippets.

View dlespiau's full-sized avatar
👾

Damien dlespiau

👾
View GitHub Profile
git_ssh_url() {
echo $1 | sed -e 's#^https://github.com/#git@github.com:#'
}
git_http_url() {
echo $1 | sed -e 's#^git@github.com:#https://github.com/#'
}
$ jk run template.js
key: 'value'
count: 42
const template = context => ({
key: 'value',
count: context.count,
});
export default [
{ path: 'foo.yaml', value: template({ count: 42 }) },
]);
@dlespiau
dlespiau / basic_test.go
Last active June 12, 2018 09:26
Sampe kube-harness test
func TestConsistentAllRequestsAnswered(t *testing.T) {
t.Parallel()
test := kube.NewTest(t).Setup()
defer test.Close()
// Create a deploymenent from a manifest file and wait for all replicas to be ready.
service := test.CreateDeploymentFromFile(test.Namespace, "service-deploy.yaml")
test.WaitForDeploymentReady(service, 1*time.Minute)
@dlespiau
dlespiau / main_test.go
Last active May 29, 2017 18:21
calc - unit-tests
func TestAdd(t *testing.T) {
tests := []struct {
a, b, expected int
}{
{0, 0, 0},
{1, 1, 2},
{-2, 1, -1},
{-1, -10, -11},
}
@dlespiau
dlespiau / main.go
Created May 29, 2017 17:38
calc - the awesome calculator
// add is tested with a unit test
func add(a, b int) int {
return a + b
}
// sub is tested by running "calc sub 2 3".
func sub(a, b int) int {
return a - b
}
@dlespiau
dlespiau / flush_profiles.go
Last active May 31, 2017 07:32
Flush Profiles to disk
type dummyTestDeps func(pat, str string) (bool, error)
func (d dummyTestDeps) MatchString(pat, str string) (bool, error) { return false, nil }
func (d dummyTestDeps) StartCPUProfile(io.Writer) error { return nil }
func (d dummyTestDeps) StopCPUProfile() {}
func (d dummyTestDeps) WriteHeapProfile(io.Writer) error { return nil }
func (d dummyTestDeps) WriteProfileTo(string, io.Writer, int) error { return nil }
func (f dummyTestDeps) ImportPath() string { return "" }
// FlushProfiles flushes test profiles to disk. It works by build and executing
@dlespiau
dlespiau / main_test.go
Last active May 28, 2017 19:04
Building coverage-instrumented programs with Go take 1
func TestMain(m *testing.M) {
// Parse the command line using the stdlib flag package so the flags
// defined in the testing package are populated. This include the
// -coverprofile flag.
flag.Parse()
// Strip command line arguments that were for the testing package and
// that are now handled. This will remove arguments that wouldn't be
// recognised when using a 3rd party command line parser like
// github.com/urfave/cli.
@dlespiau
dlespiau / test_db.py
Created May 3, 2016 17:08
Testing for pending migrations in Django
# The MIT License (MIT)
#
# Copyright (c) 2016 Damien Lespiau
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions: