|
| 1 | +// |
| 2 | +// Copyright 2026 The Chainloop Authors. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +package runners |
| 17 | + |
| 18 | +import ( |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/stretchr/testify/suite" |
| 22 | +) |
| 23 | + |
| 24 | +type chainloopSandboxSuite struct { |
| 25 | + suite.Suite |
| 26 | + runner *ChainloopSandbox |
| 27 | +} |
| 28 | + |
| 29 | +func (s *chainloopSandboxSuite) TestCheckEnv() { |
| 30 | + testCases := []struct { |
| 31 | + name string |
| 32 | + env map[string]string |
| 33 | + want bool |
| 34 | + }{ |
| 35 | + { |
| 36 | + name: "env var not set", |
| 37 | + env: map[string]string{}, |
| 38 | + want: false, |
| 39 | + }, |
| 40 | + { |
| 41 | + name: "env var set to non-empty value", |
| 42 | + env: map[string]string{"CHAINLOOP_SANDBOX": "1"}, |
| 43 | + want: true, |
| 44 | + }, |
| 45 | + { |
| 46 | + name: "env var set to empty string", |
| 47 | + env: map[string]string{"CHAINLOOP_SANDBOX": ""}, |
| 48 | + want: false, |
| 49 | + }, |
| 50 | + } |
| 51 | + |
| 52 | + for _, tc := range testCases { |
| 53 | + s.T().Run(tc.name, func(t *testing.T) { |
| 54 | + t.Setenv("CHAINLOOP_SANDBOX", "") |
| 55 | + for k, v := range tc.env { |
| 56 | + t.Setenv(k, v) |
| 57 | + } |
| 58 | + s.Equal(tc.want, s.runner.CheckEnv()) |
| 59 | + }) |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +func (s *chainloopSandboxSuite) TestListEnvVars() { |
| 64 | + s.Empty(s.runner.ListEnvVars()) |
| 65 | +} |
| 66 | + |
| 67 | +func (s *chainloopSandboxSuite) TestResolveEnvVars() { |
| 68 | + resolved, errors := s.runner.ResolveEnvVars() |
| 69 | + s.Empty(errors) |
| 70 | + s.Empty(resolved) |
| 71 | +} |
| 72 | + |
| 73 | +func (s *chainloopSandboxSuite) TestRunURI() { |
| 74 | + s.Empty(s.runner.RunURI()) |
| 75 | +} |
| 76 | + |
| 77 | +func (s *chainloopSandboxSuite) TestWorkflowFilePath() { |
| 78 | + s.Empty(s.runner.WorkflowFilePath()) |
| 79 | +} |
| 80 | + |
| 81 | +func (s *chainloopSandboxSuite) TestIsAuthenticated() { |
| 82 | + s.False(s.runner.IsAuthenticated()) |
| 83 | +} |
| 84 | + |
| 85 | +func (s *chainloopSandboxSuite) TestEnvironment() { |
| 86 | + s.Equal(Unknown, s.runner.Environment()) |
| 87 | +} |
| 88 | + |
| 89 | +func (s *chainloopSandboxSuite) TestRunnerName() { |
| 90 | + s.Equal("CHAINLOOP_SANDBOX", s.runner.ID().String()) |
| 91 | +} |
| 92 | + |
| 93 | +func (s *chainloopSandboxSuite) SetupTest() { |
| 94 | + s.runner = NewChainloopSandbox() |
| 95 | +} |
| 96 | + |
| 97 | +func TestChainloopSandboxRunner(t *testing.T) { |
| 98 | + suite.Run(t, new(chainloopSandboxSuite)) |
| 99 | +} |
0 commit comments