From 7cb47b5bdd8f532a5e0281d49556d146c68ee159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Insaurralde?= Date: Tue, 24 Feb 2026 15:23:37 -0300 Subject: [PATCH] test(controlplane): cover extractEnvVariables ordering and nil input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matías Insaurralde --- .../internal/service/attestation_test.go | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/app/controlplane/internal/service/attestation_test.go b/app/controlplane/internal/service/attestation_test.go index 42d574f10..26c71700b 100644 --- a/app/controlplane/internal/service/attestation_test.go +++ b/app/controlplane/internal/service/attestation_test.go @@ -1,5 +1,5 @@ // -// Copyright 2023 The Chainloop Authors. +// Copyright 2023-2026 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -99,3 +99,42 @@ func TestExtractMaterials(t *testing.T) { }) } } + +func TestExtractEnvVariables(t *testing.T) { + testCases := []struct { + name string + input map[string]string + want []*cpAPI.AttestationItem_EnvVariable + }{ + { + name: "returns env vars sorted by name", + input: map[string]string{ + "Z_VAR": "z", + "A_VAR": "a", + "M_VAR": "m", + }, + want: []*cpAPI.AttestationItem_EnvVariable{ + {Name: "A_VAR", Value: "a"}, + {Name: "M_VAR", Value: "m"}, + {Name: "Z_VAR", Value: "z"}, + }, + }, + { + name: "empty input", + input: map[string]string{}, + want: []*cpAPI.AttestationItem_EnvVariable{}, + }, + { + name: "nil input", + input: nil, + want: []*cpAPI.AttestationItem_EnvVariable{}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + got := extractEnvVariables(tc.input) + assert.Equal(t, tc.want, got) + }) + } +}