github.com/grailbio/base@v0.0.11/cmd/ticket-server/ec2blesser_test.go (about)

     1  // Copyright 2018 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache-2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"strings"
     9  	"testing"
    10  	"time"
    11  
    12  	"github.com/grailbio/base/cloud/ec2util"
    13  )
    14  
    15  func TestCheckPendingTime(t *testing.T) {
    16  	now := time.Now()
    17  	cases := []struct {
    18  		doc       ec2util.IdentityDocument
    19  		errPrefix string
    20  	}{
    21  		{ec2util.IdentityDocument{PendingTime: now}, ""},
    22  		{ec2util.IdentityDocument{PendingTime: now.Add(-pendingTimeWindow - time.Second)}, "launch time is too old"},
    23  		{ec2util.IdentityDocument{}, "launch time is too old"},
    24  	}
    25  
    26  	for _, c := range cases {
    27  		err := checkPendingTime(&c.doc)
    28  		if err != nil && (c.errPrefix == "" || !strings.HasPrefix(err.Error(), c.errPrefix)) {
    29  			t.Errorf("checkPendingTime: got %q, want %q", err, c.errPrefix)
    30  		}
    31  	}
    32  }