github.com/openshift-online/ocm-sdk-go@v0.1.473/authentication/main_test.go (about)

     1  /*
     2  Copyright (c) 2019 Red Hat, Inc.
     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  
    17  package authentication
    18  
    19  import (
    20  	"os"
    21  	"testing"
    22  
    23  	"github.com/openshift-online/ocm-sdk-go/logging"
    24  
    25  	. "github.com/onsi/ginkgo/v2/dsl/core"             // nolint
    26  	. "github.com/onsi/gomega"                         // nolint
    27  	. "github.com/openshift-online/ocm-sdk-go/testing" // nolint
    28  )
    29  
    30  func TestAuthentication(t *testing.T) {
    31  	RegisterFailHandler(Fail)
    32  	RunSpecs(t, "Authentication")
    33  }
    34  
    35  // Logger used for tests:
    36  var logger logging.Logger
    37  
    38  // JSON web key set used for tests:
    39  var keysBytes []byte
    40  var keysFile string
    41  
    42  var _ = BeforeSuite(func() {
    43  	var err error
    44  
    45  	// Create a temporary file containing the JSON web key set:
    46  	keysBytes = DefaultJWKS()
    47  	keysFD, err := os.CreateTemp("", "jwks-*.json")
    48  	Expect(err).ToNot(HaveOccurred())
    49  	_, err = keysFD.Write(keysBytes)
    50  	Expect(err).ToNot(HaveOccurred())
    51  	err = keysFD.Close()
    52  	Expect(err).ToNot(HaveOccurred())
    53  	keysFile = keysFD.Name()
    54  
    55  	// Create the logger that will be used by all the tests:
    56  	logger, err = logging.NewStdLoggerBuilder().
    57  		Streams(GinkgoWriter, GinkgoWriter).
    58  		Debug(true).
    59  		Build()
    60  	Expect(err).ToNot(HaveOccurred())
    61  })
    62  
    63  var _ = AfterSuite(func() {
    64  	// Delete the temporary files:
    65  	err := os.Remove(keysFile)
    66  	Expect(err).ToNot(HaveOccurred())
    67  })