Fix tests.

This commit is contained in:
Mariano Cano 2019-07-29 18:24:34 -07:00
parent b827a59e96
commit f8cacc11b1
7 changed files with 20 additions and 8 deletions

View file

@ -1,6 +1,7 @@
package provisioner package provisioner
import ( import (
"context"
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"crypto/sha256" "crypto/sha256"
@ -347,7 +348,8 @@ func TestAWS_AuthorizeSign(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := tt.aws.AuthorizeSign(tt.args.token) ctx := NewContextWithMethod(context.Background(), SignMethod)
got, err := tt.aws.AuthorizeSign(ctx, tt.args.token)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("AWS.AuthorizeSign() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("AWS.AuthorizeSign() error = %v, wantErr %v", err, tt.wantErr)
return return

View file

@ -1,6 +1,7 @@
package provisioner package provisioner
import ( import (
"context"
"crypto/sha256" "crypto/sha256"
"crypto/x509" "crypto/x509"
"encoding/hex" "encoding/hex"
@ -295,7 +296,8 @@ func TestAzure_AuthorizeSign(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := tt.azure.AuthorizeSign(tt.args.token) ctx := NewContextWithMethod(context.Background(), SignMethod)
got, err := tt.azure.AuthorizeSign(ctx, tt.args.token)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("Azure.AuthorizeSign() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("Azure.AuthorizeSign() error = %v, wantErr %v", err, tt.wantErr)
return return

View file

@ -1,6 +1,7 @@
package provisioner package provisioner
import ( import (
"context"
"crypto/sha256" "crypto/sha256"
"crypto/x509" "crypto/x509"
"encoding/hex" "encoding/hex"
@ -330,7 +331,8 @@ func TestGCP_AuthorizeSign(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := tt.gcp.AuthorizeSign(tt.args.token) ctx := NewContextWithMethod(context.Background(), SignMethod)
got, err := tt.gcp.AuthorizeSign(ctx, tt.args.token)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("GCP.AuthorizeSign() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("GCP.AuthorizeSign() error = %v, wantErr %v", err, tt.wantErr)
return return

View file

@ -1,6 +1,7 @@
package provisioner package provisioner
import ( import (
"context"
"crypto/x509" "crypto/x509"
"errors" "errors"
"strings" "strings"
@ -259,7 +260,8 @@ func TestJWK_AuthorizeSign(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if got, err := tt.prov.AuthorizeSign(tt.args.token); err != nil { ctx := NewContextWithMethod(context.Background(), SignMethod)
if got, err := tt.prov.AuthorizeSign(ctx, tt.args.token); err != nil {
if assert.NotNil(t, tt.err) { if assert.NotNil(t, tt.err) {
assert.HasPrefix(t, err.Error(), tt.err.Error()) assert.HasPrefix(t, err.Error(), tt.err.Error())
} }

View file

@ -1,6 +1,7 @@
package provisioner package provisioner
import ( import (
"context"
"crypto/x509" "crypto/x509"
"testing" "testing"
@ -21,7 +22,8 @@ func Test_noop(t *testing.T) {
assert.Equals(t, "", key) assert.Equals(t, "", key)
assert.Equals(t, false, ok) assert.Equals(t, false, ok)
sigOptions, err := p.AuthorizeSign("foo") ctx := NewContextWithMethod(context.Background(), SignMethod)
sigOptions, err := p.AuthorizeSign(ctx, "foo")
assert.Equals(t, []SignOption{}, sigOptions) assert.Equals(t, []SignOption{}, sigOptions)
assert.Equals(t, nil, err) assert.Equals(t, nil, err)
} }

View file

@ -1,6 +1,7 @@
package provisioner package provisioner
import ( import (
"context"
"crypto/x509" "crypto/x509"
"fmt" "fmt"
"strings" "strings"
@ -276,7 +277,8 @@ func TestOIDC_AuthorizeSign(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := tt.prov.AuthorizeSign(tt.args.token) ctx := NewContextWithMethod(context.Background(), SignMethod)
got, err := tt.prov.AuthorizeSign(ctx, tt.args.token)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("OIDC.Authorize() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("OIDC.Authorize() error = %v, wantErr %v", err, tt.wantErr)
return return

View file

@ -137,7 +137,7 @@ func TestTimeDuration_MarshalJSON(t *testing.T) {
want []byte want []byte
wantErr bool wantErr bool
}{ }{
{"null", TimeDuration{}, []byte("null"), false}, {"empty", TimeDuration{}, []byte(`""`), false},
{"timestamp", TimeDuration{t: tm}, []byte(`"2020-03-14T15:09:26.535897Z"`), false}, {"timestamp", TimeDuration{t: tm}, []byte(`"2020-03-14T15:09:26.535897Z"`), false},
{"duration", TimeDuration{d: 1 * time.Hour}, []byte(`"1h0m0s"`), false}, {"duration", TimeDuration{d: 1 * time.Hour}, []byte(`"1h0m0s"`), false},
{"fail", TimeDuration{t: time.Date(-1, 0, 0, 0, 0, 0, 0, time.UTC)}, nil, true}, {"fail", TimeDuration{t: time.Date(-1, 0, 0, 0, 0, 0, 0, time.UTC)}, nil, true},
@ -166,7 +166,7 @@ func TestTimeDuration_UnmarshalJSON(t *testing.T) {
want *TimeDuration want *TimeDuration
wantErr bool wantErr bool
}{ }{
{"null", args{[]byte("null")}, &TimeDuration{}, false}, {"empty", args{[]byte(`""`)}, &TimeDuration{}, false},
{"timestamp", args{[]byte(`"2020-03-14T15:09:26.535897Z"`)}, &TimeDuration{t: time.Unix(1584198566, 535897000).UTC()}, false}, {"timestamp", args{[]byte(`"2020-03-14T15:09:26.535897Z"`)}, &TimeDuration{t: time.Unix(1584198566, 535897000).UTC()}, false},
{"duration", args{[]byte(`"1h"`)}, &TimeDuration{d: time.Hour}, false}, {"duration", args{[]byte(`"1h"`)}, &TimeDuration{d: time.Hour}, false},
{"fail", args{[]byte("123")}, &TimeDuration{}, true}, {"fail", args{[]byte("123")}, &TimeDuration{}, true},