From b3434aca37eb22992781b23b7676860d860ef90d Mon Sep 17 00:00:00 2001 From: Mateusz Urbanek Date: Mon, 17 Jun 2024 17:37:32 +0200 Subject: [PATCH] test: add smoke tests to few parts of code Signed-off-by: Mateusz Urbanek --- cmd/main.go | 2 +- cmd/main_test.go | 33 +++++++++++++++ observability/tracing/tracing.go | 16 ++++++++ observability/tracing/tracing_test.go | 58 +++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 cmd/main_test.go create mode 100644 observability/tracing/tracing_test.go diff --git a/cmd/main.go b/cmd/main.go index 426c4635e..eb264caa3 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,5 +1,5 @@ /* -Copyright 2023 Akamai Technologies, Inc. +Copyright 2023-2024 Akamai Technologies, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/cmd/main_test.go b/cmd/main_test.go new file mode 100644 index 000000000..828ff6996 --- /dev/null +++ b/cmd/main_test.go @@ -0,0 +1,33 @@ +/* +Copyright 2024 Akamai Technologies, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "context" + "testing" + "time" +) + +func TestSetupObservabillity(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + shutdown := setupObservabillity(ctx) + shutdown() +} diff --git a/observability/tracing/tracing.go b/observability/tracing/tracing.go index 2708bd142..e6b8832a8 100644 --- a/observability/tracing/tracing.go +++ b/observability/tracing/tracing.go @@ -1,3 +1,19 @@ +/* +Copyright 2024 Akamai Technologies, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package tracing import ( diff --git a/observability/tracing/tracing_test.go b/observability/tracing/tracing_test.go new file mode 100644 index 000000000..616387a99 --- /dev/null +++ b/observability/tracing/tracing_test.go @@ -0,0 +1,58 @@ +/* +Copyright 2024 Akamai Technologies, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package tracing + +import ( + "context" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/sdk/resource" +) + +func TestSetup(t *testing.T) { + t.Parallel() + + for name, tc := range map[string]struct { + env map[string]string + resource *resource.Resource + }{ + "smoke": { + env: make(map[string]string), + resource: resource.Default(), + }, + } { + tc := tc + + t.Run(name, func(t *testing.T) { + for k, v := range tc.env { + t.Setenv(k, v) + } + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + shutdown, err := Setup(ctx, tc.resource) + require.NoError(t, err) + + err = shutdown(ctx) + assert.NoError(t, err) + }) + } +}