1
0
mirror of https://github.com/lfkeitel/docker-registry-auth.git synced 2025-04-19 00:24:02 +03:00
docker-registry-auth/testing_test.go
Lee Keitel 8d2535d179 First working server
All permissions are honored, hashed passwords can be used,
everything works and most of it is tested.
2017-03-15 16:36:45 -05:00

53 lines
1.6 KiB
Go

package dockerauth
/*
Source: https://github.com/benbjohnson/testing
Copyright (c) 2014 Ben Johnson
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:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
import (
"fmt"
"path/filepath"
"reflect"
"runtime"
"testing"
)
// assert fails the test if the condition is false.
func assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
if !condition {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
tb.FailNow()
}
}
// ok fails the test if an err is not nil.
func ok(tb testing.TB, err error) {
if err != nil {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error())
tb.FailNow()
}
}
// equals fails the test if exp is not equal to act.
func equals(tb testing.TB, got, wanted interface{}) {
if !reflect.DeepEqual(got, wanted) {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d:\n\n\tgot: %#v\n\n\twanted: %#v\033[39m\n\n", filepath.Base(file), line, got, wanted)
tb.FailNow()
}
}