Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyb89 committed Jan 11, 2025
1 parent 2204e0a commit c5e81d3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/tbot/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func testYAML[T any](t *testing.T, tests []testYAMLCase[T]) {
decoder := yaml.NewDecoder(b)
var unmarshalled T
require.NoError(t, decoder.Decode(&unmarshalled))
require.Equal(t, unmarshalled, tt.in, "unmarshalling did not result in same object as input")
require.Equal(t, tt.in, unmarshalled, "unmarshalling did not result in same object as input")
})
}
}
Expand Down
19 changes: 18 additions & 1 deletion lib/tbot/config/service_kubernetes_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ package config
import (
"context"

"github.com/gravitational/teleport/lib/tbot/bot"
"github.com/gravitational/trace"
"gopkg.in/yaml.v3"

"github.com/gravitational/teleport/lib/tbot/bot"
)

var (
Expand Down Expand Up @@ -142,3 +143,19 @@ func (s *KubernetesSelector) CheckAndSetDefaults() error {

return nil
}

func (s *KubernetesSelector) UnmarshalYAML(value *yaml.Node) error {
// A custom unmarshaler so Labels is consistently initialized to not-nil.
// Primarily needed for tests.
type temp KubernetesSelector
out := temp{
Labels: make(map[string]string),
}

if err := value.Decode(&out); err != nil {
return err
}

*s = KubernetesSelector(out)
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ roles:
disable_exec_plugin: true
selectors:
- name: foo
labels: {}
- name: ""
labels:
- labels:
foo: bar
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ destination:
type: memory
selectors:
- name: foo
labels: {}
7 changes: 4 additions & 3 deletions lib/tbot/service_kubernetes_v2_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (
"log/slog"
"path/filepath"

"github.com/gravitational/trace"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"

apiclient "github.com/gravitational/teleport/api/client"
"github.com/gravitational/teleport/api/client/proto"
"github.com/gravitational/teleport/api/defaults"
Expand All @@ -38,9 +42,6 @@ import (
"github.com/gravitational/teleport/lib/tbot/config"
"github.com/gravitational/teleport/lib/tbot/identity"
logutils "github.com/gravitational/teleport/lib/utils/log"
"github.com/gravitational/trace"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)

// KubernetesOutputService produces credentials which can be used to connect to
Expand Down
5 changes: 3 additions & 2 deletions lib/tbot/service_kubernetes_v2_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import (
"path/filepath"
"testing"

"github.com/gravitational/trace"
"github.com/stretchr/testify/require"

apiclient "github.com/gravitational/teleport/api/client"
"github.com/gravitational/teleport/api/client/proto"
"github.com/gravitational/teleport/api/types"
Expand All @@ -37,8 +40,6 @@ import (
"github.com/gravitational/teleport/lib/tbot/identity"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/lib/utils/golden"
"github.com/gravitational/trace"
"github.com/stretchr/testify/require"
)

// fakeKubeServerClient provides a minimal implementation of
Expand Down

0 comments on commit c5e81d3

Please sign in to comment.