tests(etcdserver): refactor
-// Copyright 2016 The etcd Authors
+// Copyright 2022 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package etcdserver
-import "testing"
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
func TestOriginAllowed(t *testing.T) {
tests := []struct {
@@ -59,11 +63,9 @@ func TestOriginAllowed(t *testing.T) {
},
}
- for i, tt := range tests {
+ for _, tt := range tests {
allowed := tt.accessController.OriginAllowed(tt.origin)
- if allowed != tt.allowed {
- t.Fatalf("#%d: allowd = %t, want %t", i, allowed, tt.allowed)
- }
+ assert.Equal(t, allowed, tt.allowed)
}
}
@@ -110,10 +112,8 @@ func TestIsHostWhitelisted(t *testing.T) {
},
}
- for i, tt := range tests {
+ for _, tt := range tests {
whitelisted := tt.accessController.IsHostWhitelisted(tt.host)
- if whitelisted != tt.whitelisted {
- t.Fatalf("#%d:whitelisted = %t, want %t", i, whitelisted, tt.whitelisted)
- }
+ assert.Equal(t, whitelisted, tt.whitelisted)
}
}
