<commit_before>/*
Copyright 2016 The Kubernetes Authors All rights reserved.

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 driver // import "k8s.io/helm/pkg/storage/driver"

import (
	rspb "k8s.io/helm/pkg/proto/hapi/release"
	"testing"
)

func TestMemoryGet(t *testing.T) {
	key := "test-1"
	rls := &rspb.Release{Name: key}

	mem := NewMemory()
	mem.Create(rls)

	res, err := mem.Get(key)
	switch {
	case err != nil:
		t.Errorf("Could not get %s: %s", key, err)
	case res.Name != key:
		t.Errorf("Expected %s, got %s", key, res.Name)
	}
}

func TestMemoryAll(t *testing.T) {
	t.Skip("MemoryAll")
}

func TestMemoryCreate(t *testing.T) {
	key := "test-1"
	rls := &rspb.Release{Name: key}

	mem := NewMemory()
	err := mem.Create(rls)

	switch {
	case err != nil:
		t.Fatalf("Failed create: %s", err)
	case mem.cache[key].Name != key:
		t.Errorf("Unexpected release name: %s", mem.cache[key].Name)
	}
}

func TestMemoryUpdate(t *testing.T) {
	key := "test-1"
	rls := &rspb.Release{Name: key}

	mem := NewMemory()
	if err := mem.Create(rls); err != nil {
		t.Fatalf("Failed create: %s", err)
	}
	if err := mem.Update(rls); err != nil {
		t.Fatalf("Failed update: %s", err)
	}
	if mem.cache[key].Name != key {
		t.Errorf("Unexpected release name: %s", mem.cache[key].Name)
	}
}

func TestMemoryDelete(t *testing.T) {
	key := "test-1"
	rls := &rspb.Release{Name: key}

	mem := NewMemory()
	if err := mem.Create(rls); err != nil {
		t.Fatalf("Failed create: %s", err)
	}

	res, err := mem.Delete(key)
	switch {
	case err != nil:
		t.Fatalf("Failed delete: %s", err)
	case mem.cache[key] != nil:
		t.Errorf("Expected nil, got %s", mem.cache[key])
	case res.Info.Status.Code != release.Status_DELETED:
		t.Errorf("Expected Status_DELETED, got %s", res.Info.Status.Code)
	}
}<commit_msg>fix panic in memory_test when release status is nil<commit_after>/*
Copyright 2016 The Kubernetes Authors All rights reserved.

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 driver // import "k8s.io/helm/pkg/storage/driver"

import (
	rspb "k8s.io/helm/pkg/proto/hapi/release"
	"testing"
)

func TestMemoryGet(t *testing.T) {
	key := "test-1"
	rls := &rspb.Release{Name: key}

	mem := NewMemory()
	mem.Create(rls)

	res, err := mem.Get(key)
	switch {
	case err != nil:
		t.Errorf("Could not get %s: %s", key, err)
	case res.Name != key:
		t.Errorf("Expected %s, got %s", key, res.Name)
	}
}

func TestMemoryAll(t *testing.T) {
	t.Skip("MemoryAll")
}

func TestMemoryCreate(t *testing.T) {
	key := "test-1"
	rls := &rspb.Release{Name: key}

	mem := NewMemory()
	err := mem.Create(rls)

	switch {
	case err != nil:
		t.Fatalf("Failed create: %s", err)
	case mem.cache[key].Name != key:
		t.Errorf("Unexpected release name: %s", mem.cache[key].Name)
	}
}

func TestMemoryUpdate(t *testing.T) {
	key := "test-1"
	rls := &rspb.Release{Name: key}

	mem := NewMemory()
	if err := mem.Create(rls); err != nil {
		t.Fatalf("Failed create: %s", err)
	}
	if err := mem.Update(rls); err != nil {
		t.Fatalf("Failed update: %s", err)
	}
	if mem.cache[key].Name != key {
		t.Errorf("Unexpected release name: %s", mem.cache[key].Name)
	}
}

func TestMemoryDelete(t *testing.T) {
	key := "test-1"
	rls := &rspb.Release{
		Name: key,
		Info: &rspb.Info{
			Status: &rspb.Status{Code: rspb.Status_DEPLOYED},
		},
	}

	mem := NewMemory()
	if err := mem.Create(rls); err != nil {
		t.Fatalf("Failed create: %s", err)
	}

	res, err := mem.Delete(key)
	switch {
	case err != nil:
		t.Fatalf("Failed delete: %s", err)
	case mem.cache[key] != nil:
		t.Errorf("Expected nil, got %s", mem.cache[key])
	case res.Info.Status.Code != rspb.Status_DELETED:
		t.Errorf("Expected Status_DELETED, got %s", res.Info.Status.Code)
	}
}
{'fraction_non_alphanumeric': 0.15617615467239526, 'fraction_numerical': 0.006015037593984963, 'mean_word_length': 3.9010526315789473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4918013', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1704, 'n_words': 500}