| 1 | // Copyright 2023 The Archivista Contributors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package configscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/ |
| 16 | |
| 17 | import ( |
| 18 | "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/" |
| 19 | "osscip-go gomod github.com/golang/go/src go1.24.0 os/" |
| 20 | "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/" |
| 21 | |
| 22 | "github.com/sirupsen/logrusscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/" |
| 23 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/" |
| 24 | ) |
| 25 | |
| 26 | func TestConfig_Processscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/TestConfig_Process().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 27 | // Set up test environment variables |
| 28 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_LISTEN_ON", "tcp://0.0.0.0:8082") |
| 29 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_READ_TIMEOUT", "300") |
| 30 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_WRITE_TIMEOUT", "300") |
| 31 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_LOG_LEVEL", "DEBUG") |
| 32 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_CORS_ALLOW_ORIGINS", "http://localhost,https://example.com") |
| 33 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_ENABLE_SPIFFE", "FALSE") |
| 34 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_SQL_STORE_CONNECTION_STRING", "root:password@tcp(localhost:3306)/testify") |
| 35 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_STORAGE_BACKEND", "BLOB") |
| 36 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_BLOB_STORE_ENDPOINT", "https://s3.example.com") |
| 37 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_BLOB_STORE_ACCESS_KEY_ID", "ACCESSKEYID") |
| 38 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_BLOB_STORE_SECRET_ACCESS_KEY_ID", "SECRETACCESSKEYID") |
| 39 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_BLOB_STORE_BUCKET_NAME", "mybucket") |
| 40 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_GRAPHQL_WEB_CLIENT_ENABLE", "FALSE") |
| 41 | |
| 42 | // Create a Config struct and call Process() |
| 43 | c := &Configscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#{} |
| 44 | err := c.Processscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#Process().() |
| 45 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 46 | |
| 47 | // Check that the expected values were read from environment variables |
| 48 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, "tcp://0.0.0.0:8082", c.ListenOnscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#ListenOn.) |
| 49 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, 300, c.ReadTimeoutscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#ReadTimeout.) |
| 50 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, 300, c.WriteTimeoutscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#WriteTimeout.) |
| 51 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, "DEBUG", c.LogLevelscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#LogLevel.) |
| 52 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, []string{"http://localhost", "https://example.com"}, c.CORSAllowOriginsscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#CORSAllowOrigins.) |
| 53 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Falsescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/False().(t, c.EnableSPIFFEscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#EnableSPIFFE.) |
| 54 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, "root:password@tcp(localhost:3306)/testify", c.SQLStoreConnectionStringscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#SQLStoreConnectionString.) |
| 55 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, "BLOB", c.StorageBackendscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#StorageBackend.) |
| 56 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, "https://s3.example.com", c.BlobStoreEndpointscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#BlobStoreEndpoint.) |
| 57 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, "ACCESSKEYID", c.BlobStoreAccessKeyIdscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#BlobStoreAccessKeyId.) |
| 58 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, "SECRETACCESSKEYID", c.BlobStoreSecretAccessKeyIdscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#BlobStoreSecretAccessKeyId.) |
| 59 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, "mybucket", c.BlobStoreBucketNamescip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#BlobStoreBucketName.) |
| 60 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Falsescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/False().(t, c.GraphqlWebClientEnablescip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#GraphqlWebClientEnable.) |
| 61 | |
| 62 | // Clean up environment variables |
| 63 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_LISTEN_ON") |
| 64 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_READ_TIMEOUT") |
| 65 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_WRITE_TIMEOUT") |
| 66 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_LOG_LEVEL") |
| 67 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_CORS_ALLOW_ORIGINS") |
| 68 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_ENABLE_SPIFFE") |
| 69 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_SQL_STORE_CONNECTION_STRING") |
| 70 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_STORAGE_BACKEND") |
| 71 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_FILE_SERVE_ON") |
| 72 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_FILE_DIR") |
| 73 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_BLOB_STORE_ENDPOINT") |
| 74 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_BLOB_STORE_ACCESS_KEY_ID") |
| 75 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_BLOB_STORE_SECRET_ACCESS_KEY_ID") |
| 76 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_BLOB_STORE_BUCKET_NAME") |
| 77 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_ENABLE_GRAPHQL") |
| 78 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_GRAPHQL_WEB_CLIENT_ENABLE") |
| 79 | } |
| 80 | |
| 81 | func TestConfig_DeprecationAndPrecedencescip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/TestConfig_DeprecationAndPrecedence().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 82 | // Set up test environment variables |
| 83 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVIST_LISTEN_ON", "tcp://0.0.0.0:8082") |
| 84 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVIST_LOG_LEVEL", "DEBUG") |
| 85 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVIST_CORS_ALLOW_ORIGINS", "http://localhost:8080") |
| 86 | |
| 87 | // os.Setenv("ARCHIVISTA_LOG_LEVEL", "INFO") |
| 88 | // os.Setenv("ARCHIVISTA_CORS_ALLOW_ORIGINS", "http://localhost,https://example.com") |
| 89 | |
| 90 | // Set up log output capturing |
| 91 | var output bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 92 | logrusscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/.SetOutputscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/SetOutput().(&output) |
| 93 | defer func() { logrusscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/.SetOutputscip-go gomod github.com/sirupsen/logrus v1.9.3 `github.com/sirupsen/logrus`/SetOutput().(osscip-go gomod github.com/golang/go/src go1.24.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.24.0 os/Stderr.) }() |
| 94 | |
| 95 | // Create a Config struct and call Process() |
| 96 | c := &Configscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#{} |
| 97 | err := c.Processscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#Process().() |
| 98 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 99 | |
| 100 | //check that the non deprecated environment variables work |
| 101 | |
| 102 | // Check that the deprecated variables work |
| 103 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, "tcp://0.0.0.0:8082", c.ListenOnscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#ListenOn.) |
| 104 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, "DEBUG", c.LogLevelscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#LogLevel.) |
| 105 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, []string{"http://localhost:8080"}, c.CORSAllowOriginsscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#CORSAllowOrigins.) |
| 106 | |
| 107 | // Check that the appropriate error is returned if both old and new prefixes are used |
| 108 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVIST_LISTEN_ON", "tcp://0.0.0.0:8083") |
| 109 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Setenvscip-go gomod github.com/golang/go/src go1.24.0 os/Setenv().("ARCHIVISTA_LISTEN_ON", "tcp://0.0.0.0:8084") |
| 110 | c = &Configscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#{} |
| 111 | err = c.Processscip-go gomod github.com/in-toto/archivista . `github.com/in-toto/archivista/pkg/config`/Config#Process().() |
| 112 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 113 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, "both deprecated and new environment variables are being used. Please use only the new environment variables", err.Error()) |
| 114 | |
| 115 | // Check that the deprecated environment variables were logged |
| 116 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Contains().(t, output.Stringscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#String().(), "Using deprecated environment variable ARCHIVIST_LOG_LEVEL") |
| 117 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Contains().(t, output.Stringscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#String().(), "Using deprecated environment variable ARCHIVIST_CORS_ALLOW_ORIGINS") |
| 118 | |
| 119 | // Clean up environment variables |
| 120 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVIST_LISTEN_ON") |
| 121 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVIST_LOG_LEVEL") |
| 122 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_LOG_LEVEL") |
| 123 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVIST_CORS_ALLOW_ORIGINS") |
| 124 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_CORS_ALLOW_ORIGINS") |
| 125 | osscip-go gomod github.com/golang/go/src go1.24.0 os/.Unsetenvscip-go gomod github.com/golang/go/src go1.24.0 os/Unsetenv().("ARCHIVISTA_LISTEN_ON") |
| 126 | } |